package com.danco.training.zaneuskaya.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author Zaneuskaya Aliaksandra
 *
 */
@Entity
@Table(name = "message")
public class Message implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6962363675466076408L;

	@Id
	@GeneratedValue
	@Column(name = "message_id")
	private Integer messageId;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "sender_fk", referencedColumnName = "user_id", updatable = false)
	private User sender;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "receiver_fk", referencedColumnName = "user_id", updatable = false)
	private User receiver;

	@Column(name = "message_time")
	@Temporal(value = TemporalType.TIMESTAMP)
	private Date messageTime;

	@Column(name = "message_subject")
	private String messageSubject;

	@Column(name = "message_text")
	private String messageText;

	@Column(name = "readed")
	private boolean readed;

	public Integer getMessageId() {
		return messageId;
	}

	public void setMessageId(Integer messageId) {
		this.messageId = messageId;
	}

	public User getSender() {
		return sender;
	}

	public void setSender(User sender) {
		this.sender = sender;
	}

	public User getReceiver() {
		return receiver;
	}

	public void setReceiver(User receiver) {
		this.receiver = receiver;
	}

	public Date getMessageTime() {
		return messageTime;
	}

	public void setMessageTime(Date messageTime) {
		this.messageTime = messageTime;
	}

	public String getMessageSubject() {
		return messageSubject;
	}

	public void setMessageSubject(String messageSubject) {
		this.messageSubject = messageSubject;
	}

	public String getMessageText() {
		return messageText;
	}

	public void setMessageText(String messageText) {
		this.messageText = messageText;
	}

	public boolean isReaded() {
		return readed;
	}

	public void setReaded(boolean readed) {
		this.readed = readed;
	}

	@Override
	public int hashCode() {
		return getMessageId();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Message) {
			Message other = (Message) obj;
			return other.getMessageId() == messageId;
		}
		return false;
	}

}
